from APP.app.tableparse.crud.excel_user_crud import ExcelUserDao
from APP.app.tableparse.models.exceluser import ExcelUser
from APP.app.tableparse.schemas.excel_user_schema import ExcelUserSchema
from APP.database.mysql import async_db_session

class ExcelUserServices:

    @staticmethod
    async def create_excel_user(data_rows:list) -> ExcelUser:
        """
        创建Excel用户
        :param obj_in: Excel用户数据
        :return: 创建的Excel用户对象
        """
        # 准备批量插入数据
        xlsx_data = []
        for row in data_rows:
            xlsx_data.append(ExcelUserSchema(
                username=row["姓名"],
                age=row["年龄"],
                department=row["部门"]
            ))

        async with async_db_session.begin() as db:

            return await ExcelUserDao.create_excel_user(db, xlsx_data)


ExcelUserService: ExcelUserServices = ExcelUserServices()
